package com.sojson.controller.po;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.sojson.entity.po.RoleMenu;
import com.sojson.result.Result;
import com.sojson.service.RoleMenuService;

/**
 * 角色和菜单关联表控制器
 * 
 * @author liu
 * @date 2021-04-13
 */
// @Api(tags = "角色和菜单关联表管理")
// @RestController
// @RequestMapping(value = "/roleMenu")
public class RoleMenuController {

    @Resource
    private RoleMenuService roleMenuServiceImpl;

    /**
     * 单条插入
     * 
     * @param roleMenu
     * @return
     * @throws SQLException
     */
    @RequestMapping(value = "/insert", method = RequestMethod.POST)
    public Object insert(@RequestBody RoleMenu roleMenu) throws SQLException {
        roleMenuServiceImpl.insert(roleMenu);
        return Result.success();
    }

    /**
     * 批量插入
     * 
     * @param roleMenu
     * @return
     * @throws SQLException
     */
    @RequestMapping(value = "/insertList", method = RequestMethod.POST)
    public Object insertList(@RequestBody RoleMenu roleMenu) throws SQLException {
        return Result.success(roleMenuServiceImpl.insertList(roleMenu));
    }

    /**
     * 通过对象批量删除(物理删除)
     * 
     * @param roleMenu
     * @return
     * @throws SQLException
     */
    @RequestMapping(value = "/deleteByDto", method = RequestMethod.POST)
    public Object deleteByDto(@RequestBody RoleMenu roleMenu) throws SQLException {
        return Result.success(roleMenuServiceImpl.deleteByDto(roleMenu));
    }

    /**
     * 统计全部数量
     * 
     * @return
     * @throws SQLException
     */
    @RequestMapping(value = "/countAll", method = RequestMethod.GET)
    public Object countAll() throws SQLException {
        int countAll = roleMenuServiceImpl.countAll();
        return Result.success(countAll);
    }

    /**
     * 查询所有
     * 
     * @return
     * @throws SQLException
     */
    @RequestMapping(value = "/findAll", method = RequestMethod.GET)
    public Object findAll() throws SQLException {
        List<RoleMenu> findAll = roleMenuServiceImpl.findAll();
        return Result.success(findAll);
    }

    /**
     * 根据对象统计数量
     * 
     * @param roleMenu
     * @return
     * @throws SQLException
     */
    @RequestMapping(value = "/countByDto", method = RequestMethod.POST)
    public Object countByDto(@RequestBody RoleMenu roleMenu) throws SQLException {
        int countByDto = roleMenuServiceImpl.countByDto(roleMenu);
        return Result.success(countByDto);
    }

    /**
     * 根据对象查询
     * 
     * @param roleMenu
     * @return
     * @throws SQLException
     */
    @RequestMapping(value = "/findByDto", method = RequestMethod.POST)
    public Object findByDto(@RequestBody RoleMenu roleMenu) throws SQLException {
        List<RoleMenu> findByDto = roleMenuServiceImpl.findByDto(roleMenu);
        return Result.success(findByDto);
    }

    /**
     * 通过menuId删除(物理删除)
     * 
     * @param menuId
     * @return
     * @throws SQLException
     */
    @RequestMapping(value = "/deleteByMenuId", method = RequestMethod.POST)
    public Object deleteByMenuId(Integer menuId) throws SQLException {
        roleMenuServiceImpl.deleteByMenuId(menuId);
        return Result.success();
    }

    /**
     * 通过menuId列表删除(物理删除)
     * 
     * @param menuIds
     * @return
     * @throws SQLException
     */
    @RequestMapping(value = "/deleteByMenuIdList", method = RequestMethod.POST)
    public Object deleteByMenuIdList(@RequestParam("menuIds[]") ArrayList<Integer> menuIds) throws SQLException {
        return Result.success(roleMenuServiceImpl.deleteByMenuIdList(menuIds));
    }

    /**
     * 通过menuId更新(全部更新)
     * 
     * @param roleMenu
     * @return
     * @throws SQLException
     */
    @RequestMapping(value = "/updateByMenuId", method = RequestMethod.POST)
    public Object updateByMenuId(@RequestBody RoleMenu roleMenu) throws SQLException {
        roleMenuServiceImpl.updateByMenuId(roleMenu);
        return Result.success();
    }

    /**
     * 通过menuId列表更新(全部更新)(更新内容相同)
     * 
     * @param roleMenu
     * @return
     * @throws SQLException
     */
    @RequestMapping(value = "/updateStaticByMenuIdList", method = RequestMethod.POST)
    public Object updateStaticByMenuIdList(@RequestBody RoleMenu roleMenu) throws SQLException {
        return Result.success(roleMenuServiceImpl.updateStaticByMenuIdList(roleMenu));
    }

    /**
     * 通过menuId列表更新(全部更新)(更新内容不相同)
     * 
     * @param roleMenu
     * @return
     * @throws SQLException
     */
    @RequestMapping(value = "/updateChangeByMenuIdList", method = RequestMethod.POST)
    public Object updateChangeByMenuIdList(@RequestBody RoleMenu roleMenu) throws SQLException {
        return Result.success(roleMenuServiceImpl.updateChangeByMenuIdList(roleMenu));
    }

    /**
     * 通过menuId更新(局部更新)
     * 
     * @param roleMenu
     * @return
     * @throws SQLException
     */
    @RequestMapping(value = "/updatePartialByMenuId", method = RequestMethod.POST)
    public Object updatePartialByMenuId(@RequestBody RoleMenu roleMenu) throws SQLException {
        roleMenuServiceImpl.updatePartialByMenuId(roleMenu);
        return Result.success();
    }

    /**
     * 通过menuId列表更新(局部更新)(更新内容相同)
     * 
     * @param roleMenu
     * @return
     * @throws SQLException
     */
    @RequestMapping(value = "/updateStaticPartialByMenuIdList", method = RequestMethod.POST)
    public Object updateStaticPartialByMenuIdList(@RequestBody RoleMenu roleMenu) throws SQLException {
        return Result.success(roleMenuServiceImpl.updateStaticPartialByMenuIdList(roleMenu));
    }

    /**
     * 通过menuId列表更新(局部更新)(更新内容不相同)
     * 
     * @param roleMenu
     * @return
     * @throws SQLException
     */
    @RequestMapping(value = "/updateChangePartialByMenuIdList", method = RequestMethod.POST)
    public Object updateChangePartialByMenuIdList(@RequestBody RoleMenu roleMenu) throws SQLException {
        return Result.success(roleMenuServiceImpl.updateChangePartialByMenuIdList(roleMenu));
    }

    /**
     * 通过menuId查询
     * 
     * @param menuId
     * @return
     * @throws SQLException
     */
    @RequestMapping(value = "/findByMenuId", method = RequestMethod.GET)
    public Object findByMenuId(Integer menuId) throws SQLException {
        RoleMenu findByMenuId = roleMenuServiceImpl.findByMenuId(menuId);
        return Result.success(findByMenuId);
    }

    /**
     * 通过menuId列表查询
     * 
     * @param menuIds
     * @return
     * @throws SQLException
     */
    @RequestMapping(value = "/findByMenuIdList", method = RequestMethod.GET)
    public Object findByMenuIdList(@RequestParam("menuIds[]") ArrayList<Integer> menuIds) throws SQLException {
        ArrayList<RoleMenu> findByMenuIdList = roleMenuServiceImpl.findByMenuIdList(menuIds);
        return Result.success(findByMenuIdList);
    }

    /**
     * 通过对象查询menuId列表
     * 
     * @param roleMenu
     * @return
     * @throws SQLException
     */
    @RequestMapping(value = "/findMenuIdByDto", method = RequestMethod.POST)
    public Object findMenuIdByDto(@RequestBody RoleMenu roleMenu) throws SQLException {
        ArrayList<Integer> findMenuIdByDto = roleMenuServiceImpl.findMenuIdByDto(roleMenu);
        return Result.success(findMenuIdByDto);
    }

    /**
     * 清空数据(物理清空)
     * 
     * @return
     * @throws SQLException
     */
    @RequestMapping(value = "/clear", method = RequestMethod.POST)
    public Object clear() throws SQLException {
        roleMenuServiceImpl.clear();
        return Result.success();
    }

}